package com.wangy.sct.serviceuser.app.rest;

import com.wangy.sct.common.core.InvokeResult;
import com.wangy.sct.serviceuser.api.model.request.UserServiceReq;
import com.wangy.sct.serviceuser.api.model.response.UserServiceResp;
import com.wangy.sct.serviceuser.api.service.UserServiceFeign;
import com.wangy.sct.serviceuser.app.service.UserService;
import org.apache.commons.lang3.Validate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: UserRest <br/>
 * Description:  <br/>
 *
 * @author wangyue
 * @version V1.0.0
 * @date 2018/11/5 6:20 PM
 */
@RestController
public class UserRest implements UserServiceFeign {

	@Autowired
	private UserService userService;

	/**
	 * @Description:
	 * @param: [userId]
	 * @return: com.wangy.sct.common.InvokeResult<com.wangy.sct.serviceuser.api.model.response.UserServiceResp>
	 * @author: wangyue
	 * @Date: 2018/11/9 3:20 PM
	 */
	@GetMapping(value = "/query/{userId}", produces = MediaType.APPLICATION_JSON_VALUE)
	public InvokeResult queryUser(@PathVariable("userId") String userId) {
		Validate.notBlank(userId);
		InvokeResult<UserServiceResp> invokeResult = new InvokeResult<>();
		UserServiceResp userInfoResp = userService.queryById(userId);
		invokeResult.setData(userInfoResp);
		return invokeResult;
	}

	/**
	 * @Description:
	 * @param: [userReq]
	 * @return: com.wangy.sct.common.InvokeResult<com.wangy.sct.serviceuser.api.model.response.UserServiceResp>
	 * @author: wangyue
	 * @Date: 2018/11/9 3:20 PM
	 */
	@PostMapping(value = "/query", produces = MediaType.APPLICATION_JSON_VALUE)
	public InvokeResult queryUser(@RequestBody UserServiceReq userReq) {
		Validate.notBlank(userReq.getUserName());
		Validate.notBlank(userReq.getPassWord());
		InvokeResult<UserServiceResp> invokeResult = new InvokeResult<>();
		UserServiceResp userInfoResp = userService.queryByNameAndPwd(userReq.getUserName(), userReq.getPassWord());
		return invokeResult.setData(userInfoResp);
	}

	/**
	 * @Description:
	 * @param: [userId]
	 * @return: com.wangy.sct.common.InvokeResult<com.wangy.sct.serviceuser.api.model.response.UserServiceResp>
	 * @author: wangyue
	 * @Date: 2018/11/9 3:20 PM
	 */
	@GetMapping(value = "/user/queryAuthority/{userId}", produces = MediaType.APPLICATION_JSON_VALUE)
	public InvokeResult queryUserAuthority(@PathVariable("userId") String userId) {
		Validate.notBlank(userId);
		InvokeResult<UserServiceResp> invokeResult = new InvokeResult<>();

		return invokeResult;
	}

}
